package elka.sag.logisticsystem.actor;


import org.apache.log4j.Logger;

import elka.sag.logisticsystem.bean.Article;
import elka.sag.logisticsystem.bean.Order;
import elka.sag.logisticsystem.bean.Order.OrderStatus;
import elka.sag.logisticsystem.message.FactoryMessage;
import elka.sag.logisticsystem.message.SimpleMessage;

public class FactoryActor extends BaseActor {
	public static final String FACTORY_ACTOR_CLASS = "elka.sag.logisticsystem.actor.FactoryActor";
	
	private final static Logger LOGGER = Logger.getLogger(FactoryActor.class);
	
	protected void processMessage(SimpleMessage msg) throws Exception {
		FactoryMessage message = (FactoryMessage) msg;
		Order order = repositoryService.getOrderById(message.getOrderId());
		
		LOGGER.info(getClass().getSimpleName() + ": Zlecenie produkcji towarow dla zamowienia, orderId: " + message.getOrderId());
		
		for(Article article : message.getArticles()) {
			LOGGER.info(getClass().getSimpleName() + ": Przyjeto zlecenie produkcji towaru, id: " + article.getId() + " nazwa: " + article.getName());
		}
		
		OrderStatus newStatus = OrderStatus.FACTORY;
		order.setStatus(newStatus);
		order.setProcess(true);
		
		//tylko zmiana statusu
		repositoryService.updateOrderStatusAndProcess(order);
	}
}
